// EventMembership.cs
// Facebook/Framework/Service
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Facebook.Service.Core;

namespace Facebook.Service {

    /// <summary>
    /// Represents the membership list of a Facebook group.
    /// </summary>
    public sealed class EventMembership : Membership {

        private bool _attendingTransformed;
        private bool _declinedTransformed;
        private bool _unsureTransformed;
        private bool _notRepliedUsersTransformed;

        internal EventMembership(Hashtable membershipState)
            : base(membershipState) {
        }

        /// <summary>
        /// The user IDs of those who accepted the event.
        /// </summary>
        public ICollection<string> AttendingUsers {
            get {
                if (_attendingTransformed == false) {
                    return TransformAttending();
                }
                return (ICollection<string>)this["attending"];
            }
        }

        /// <summary>
        /// The user IDs of those who declined the event.
        /// </summary>
        public ICollection<string> DeclinedUsers {
            get {
                if (_declinedTransformed == false) {
                    return TransformDeclined();
                }
                return (ICollection<string>)this["declined"];
            }
        }

        /// <summary>
        /// The user IDs of those who haven't responded.
        /// </summary>
        public ICollection<string> NotRepliedUsers {
            get {
                if (_notRepliedUsersTransformed == false) {
                    return TransformNotRepliedUsers();
                }
                return (ICollection<string>)this["not_replied"];
            }
        }

        /// <summary>
        /// The user IDs of those who are unsure about the event.
        /// </summary>
        public ICollection<string> UnsureUsers {
            get {
                if (_unsureTransformed == false) {
                    return TransformUnsure();
                }
                return (ICollection<string>)this["unsure"];
            }
        }

        private ICollection<string> TransformAttending() {
            Debug.Assert(_attendingTransformed == false);

            ArrayList attendingListState = (ArrayList)this["attending"];
            ICollection<string> attending = TransformUserList(attendingListState);

            this["attending"] = attending;
            _attendingTransformed = true;

            return attending;
        }

        private ICollection<string> TransformDeclined() {
            Debug.Assert(_declinedTransformed == false);

            ArrayList declinedListState = (ArrayList)this["declined"];
            ICollection<string> declined = TransformUserList(declinedListState);

            this["declined"] = declined;
            _declinedTransformed = true;

            return declined;
        }

        private ICollection<string> TransformNotRepliedUsers() {
            Debug.Assert(_notRepliedUsersTransformed == false);

            ArrayList notRepliedListState = (ArrayList)this["not_replied"];
            ICollection<string> notRepliedUsers = TransformUserList(notRepliedListState);

            this["not_replied"] = notRepliedUsers;
            _notRepliedUsersTransformed = true;

            return notRepliedUsers;
        }

        private ICollection<string> TransformUnsure() {
            Debug.Assert(_unsureTransformed == false);

            ArrayList unsureListState = (ArrayList)this["unsure"];
            ICollection<string> unsure = TransformUserList(unsureListState);

            this["unsure"] = unsure;
            _unsureTransformed = true;

            return unsure;
        }
    }
}
